﻿using System;
using System.Threading;
using System.Windows.Controls;
using System.Windows.Threading;
using BlockMix.Utilities;

namespace BlockMix.GamePanels
{
    /// <summary>
    /// Interaction logic for LoadingPanel.xaml
    /// </summary>
    public partial class LoadingPanel : UserControl
    {
        public LoadingPanel()
        {
            InitializeComponent();
        }

        public event EventHandler LoadingSuccess;
        public event EventHandler LoadingFailed;

        #region Methods

        internal void Start()
        {
            Dispatcher.BeginInvoke(new Action(InternalStart));
        }

        private void InternalStart()
        {
            try
            {
                Thread.Sleep(3000);
                Generic.RaiseEvent(LoadingSuccess, this, EventArgs.Empty);
            }
            catch
            {
                Generic.RaiseEvent(LoadingFailed, this, EventArgs.Empty);
                throw;
            }
        }

        #endregion
    }
}
